<template>
    <div>
        <el-card>
            <div slot="header" class="clearfix">
                <span class="title">生产许可证</span>
            </div>
            <el-row style='margin-top: 20px'>
                <el-col :span="24">
                    <el-table :data='tableData' border stripe>
                        <el-table-column prop='license' label='生产许可证' align='center'></el-table-column>
                        <el-table-column  label='操作' width='120px' align='center'>
                            <template slot-scope='scope'>
                                <el-button type='text' @click='handleClick(scope.row)'>修改</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
        </el-card>
        <el-dialog title='修改' :visible.sync='dialogVisible'>
            <el-form :model='form' label-width='100px'>
                <el-form-item label='生产许可证'>
                    <el-input v-model='form.license'></el-input>
                </el-form-item>
            </el-form>
            <span slot='footer' class='dialog-footer'>
                <el-button @click='dialogVisible = false'>取 消</el-button>
                <el-button type='primary' @click='confirm'>确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import { getProdLicense, updateOrAddProdLicense } from '@/request/api';

export default {
    name: 'productLicence',
    data(){
        return{
            dialogVisible:false,
            form:{
                id:'',
                license:''
            },
            tableData:[
                {
                    license:''
                }
            ]
        }
    },
    mounted() {
        this.getTableData()
    },
    methods:{
        async getTableData(){
            const res = await getProdLicense('')
            console.log(res);
            if(res.code == 200){
                this.tableData = res.data
            }else{
                this.$message.error('修改失败，请稍后再试')
            }
        },
        async confirm(){
            const res = await updateOrAddProdLicense(this.form)
            if(res.code == 200){
                this.$message.success('修改成功')
                this.dialogVisible = false
                this.getTableData()
            }else{
                this.$message.error('修改失败，请稍后再试')
                this.getTableData()
            }
        },
        handleClick(row){
            this.form.id = row.id
            this.form.license = row.license
            this.dialogVisible = true
        }
    }

};
</script>
<style scoped lang='less'>

</style>
